package com.nondo.dean.order.mapper;


import com.nondo.dean.order.domain.OrderSubject;
import com.nondo.dean.order.model.param.OrderSubjectSearchParam;
import com.nondo.dean.order.model.result.OrderSubjectDetailResult;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author xiaofan
 * @Description:
 * @throws
 * @date 2018-04-2010:20
 * @Version 0.1
 */
@Component
public interface OrderSubjectExtendsMapper {

    /**
     * 订单搜索列表条数统计
     * @param orderSubjectSearchParam
     * @return
     */
    @SelectProvider(type=OrderSubjectExtendsSqlProvider.class, method="countByExample")
    long countByExample(OrderSubjectSearchParam orderSubjectSearchParam);


    /**
     * 订单搜索列表
     * @param orderSubjectSearchParam
     * @param rowBounds
     * @return
     */
    @SelectProvider(type=OrderSubjectExtendsSqlProvider.class, method="selectByExample")
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="order_code", property="orderCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
            @Result(column="user_no", property="userNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_telphone", property="userTelphone", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_address", property="userAddress", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_region_code", property="userRegionCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="order_take_user", property="orderTakeUser", jdbcType=JdbcType.VARCHAR),
            @Result(column="sap_code", property="sapCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="amount", property="amount", jdbcType=JdbcType.DECIMAL),
            @Result(column="note", property="note", jdbcType=JdbcType.VARCHAR),
            @Result(column="sale_guide", property="saleGuide", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_type", property="userType", jdbcType=JdbcType.VARCHAR),
            @Result(column="delivery_user", property="deliveryUser", jdbcType=JdbcType.VARCHAR),
            @Result(column="contract", property="contract", jdbcType=JdbcType.VARCHAR),
            @Result(column="business_code", property="businessCode", jdbcType=JdbcType.VARCHAR),
            @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="platform", property="platform", jdbcType=JdbcType.INTEGER),
            @Result(column="audit_status", property="auditStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="payment", property="payment", jdbcType=JdbcType.INTEGER),
            @Result(column="online_pay", property="onlinePay", jdbcType=JdbcType.INTEGER),
            @Result(column="special_amount", property="specialAmount", jdbcType=JdbcType.DECIMAL),
            @Result(column="create_by", property="createBy", jdbcType=JdbcType.BIGINT),
            @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_by", property="updateBy", jdbcType=JdbcType.BIGINT),
            @Result(column="update_date", property="updateDate", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="del_flag", property="delFlag", jdbcType=JdbcType.CHAR)
    })
    List<OrderSubject> selectByExampleWithRowbounds(OrderSubjectSearchParam orderSubjectSearchParam, RowBounds rowBounds);


    /**
     * 订单明细
     * @param orderId
     * @return
     */
    @Select("select o1.*,(select product.software_flag from dean_product_db.product product " +
            "where o1.product_code=product.code and IFNULL(o1.up_id,'')='') as prodisrt," +
            "(select o2.product_code from order_detail o2  where o1.up_id=o2.id and IFNULL(o2.up_id,'') <> '') as up_code " +
            "from order_detail o1 where o1.del_flag=0 and o1.order_id=#{orderId,jdbcType=INTEGER} ORDER BY o1.id")
    List<OrderSubjectDetailResult> selectByExample(Integer orderId);

}

